﻿
CREATE PROCEDURE [dbo].[GLUPDATE] 
       @Date DATETIME,
       @Entity VARCHAR(4),
       @Filial VARCHAR(4),
       @Subsidiary VARCHAR(12),
	   @Money DECIMAL(18,0),
       @Sector VARCHAR(4),
       @Line VARCHAR(6),
       @Value DECIMAL(18,0),
       @TRANSACTIONTYPE CHAR(1),
       @TRANSACTIONCODE DECIMAL(5),
       @OPINPUT VARCHAR(4),
       @OPAUTH VARCHAR(4),
       @MODULE VARCHAR(4),
       @PROVE VARCHAR(5),
       @EVENTCODE VARCHAR(7),
       @EVENTNUMBER VARCHAR(10),
       @CONTABILITYDATE DATETIME = null,
       @HISTORICONE VARCHAR(65),
       @HISTORICTWO VARCHAR(65),
       @REPORTFLAG BIT 
AS

declare @SubsidiaryId int
SELECT @SubsidiaryId = MAX(ID) FROM SUBSIDIARY WHERE CODE = @SUBSIDIARY

declare @SectorId int
SELECT @SectorId = MAX(ID) FROM SECTOR WHERE CODE = @SECTOR

INSERT INTO GL
(
       [Date],
       [Entity],
       [Filial],
       [SubsidiaryId],
       [Money],
       [SectorId],
       [Line],
       [Value],
       [TransactionType],
       [TransactionCode],
       [OPInput],
       [OPAuth],
       [Module],
       [Prove],
       [EventCode],
       [EventNumber],
       [ContabilityDate],
       [HistoricOne],
       [HistoricTwo],
       [ReportFlag]
)
VALUES
(
       @DATE,
       @ENTITY,
       @FILIAL,
       @SubsidiaryId,
       @MONEY,
       @SectorId,
       @LINE,
       @VALUE,
       @TRANSACTIONTYPE,
       @TRANSACTIONCODE,
       @OPINPUT,
       @OPAUTH,
       @MODULE,
       @PROVE,
       @EVENTCODE,
       @EVENTNUMBER,
       @CONTABILITYDATE,
       @HISTORICONE,
       @HISTORICTWO,
       @REPORTFLAG)